import Vuex, {Store} from "vuex"
import Vue from "vue";

// 准备actions 用于响应组件中的动作
const actions = {
    /**
     *
     * @param context
     * @param value
     * 没有第三个参数了
     */
    jia(context, value) {
        console.log("actions - jia调用")
        context.commit("JIA", value)
    },
    jian(context, value) {
        console.log("actions - jian调用")
        context.commit("JIAN", value)
    },
    jiaOdd(context, value) {
        if (context.state.sum % 2 !== 0) {
            console.log("actions - jiaOdd调用")
            context.commit("JIAODD", value)
        }
    }
}

// 准备mutations 用于操作数据(state)
const mutations = {
    JIA(state, value) {
        console.log("mutations - JIA调用")
        state.sum += value
    },
    JIAN(state, value) {
        console.log("mutations - JIA调用")
        state.sum -= value
    },
    JIAODD(state, value) {
        console.log("mutations - JIA调用")
        state.sum += value
    }
}

// 准备state  用于存储数据
const state = {
    sum: 0,
    school: "冯镠霖学校",
    subject: "前端"
}

// 准备getters  用于将state中的数据进行加工
const getters = {
    bigSum(state) {
        return state.sum * 10
    }
}

Vue.use(Vuex)

let store = new Store({
    actions,
    mutations,
    state,
    getters
});

export default store